//建立 连接到MongoDB的连接

const { MongoClient } = require("mongodb");

// 导入模块
constMongoClient = require("mongodb").MongoClient;
//连接 url
const url = 'mongodb://localhost:27017';
// const dbName = 'runoob';
const dbName = 'testmgdb';



MongoClient.connect(url, {
    useNewUrlParser: true
}, (err, client) => {
    if (err) throw err;
    console.log("成功连接到MongoDB服务器");
    const db = client.db(dbName); //选择一个数据库
    console.log(db);
    client.close() //关闭连接
})